import {v4 as uuid} from 'uuid'

//获取临时标识，逻辑：有就用；没有就造一个，随后再存进去
export function getUserTempId(){
	//尝试从local中读取用户临时标识
	// console.log('我要从local中尝试读取userTempId了')
	const userTempId = localStorage.getItem('userTempId')
	if(userTempId){
		//有就用
		return userTempId
	}else{
		//没有就生成
		const newUserTempId = uuid()
		// 生成新的标识，并存入local中
		localStorage.setItem('userTempId',newUserTempId)
		return newUserTempId
	}
}

//保存用户token到localStoragre中
export function saveUserToken2Local(token){
	localStorage.setItem('userToken',token)
}

//从localStoragre中读取用户token
export function getUserTokenFromLocal(){
	return localStorage.getItem('userToken')
}

//从localStoragre删除用户token
export function deleteUserTokenInLocal(){
	return localStorage.removeItem('userToken')
}